{% extends "base.html" %}

{% block center_show %}
    <div class="admin-login-background">
        <div class="layui-row">
            <div class="layui-col-md12">
                <div class="layui-form login-form">
{#                    <a id="register" href="javascript:">注册</a>#}
                    <form method="post" class="layui-form" action="/user/login">
                        <div class="layui-form-item logo-title">
                            <h1>登录</h1>
                        </div>
{#                        <div class="layui-form-item" style="color: #0a0e14">#}
{#                            <label class="layui-form-label"></label>#}
{#                              <select>#}
{#                                <option value="2" selected="">学生</option>#}
{#                                <option value="1">老师</option>#}
{#                                <option value="0">管理员</option>#}
{#                              </select>#}
{#                        </div>#}
                        <div class="layui-form-item">
                            <label class="layui-icon layui-icon-username" for="username"></label>
                            <input type="text" name="username" lay-verify="required" placeholder="账号" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-icon layui-icon-password" for="password"></label>
                            <input type="password" name="password" lay-verify="required" placeholder="密码" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-form-item">
                            <button type="button" class="layui-btn layui-btn-normal layui-btn-fluid" lay-submit lay-filter="login">登 入</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
{% endblock %}

{% block script %}
<script>
    //JavaScript代码区域
    layui.use(['form', 'element', 'layer'], function () {
        var element = layui.element;
        var layer = layui.layer;
        var form = layui.form;

          //监听提交
          form.on('submit(login)', function(data){
            {#layer.msg(JSON.stringify(data.field));#}
              let index = layer.load();
              $.post(
                  "/user/login",
                  {
                      username: data.field.username,
                      password: data.field.password
                  },
                  function (data, status) {
                      {#console.log(data);#}
                      layer.close(index);
                      if(data.code == 0){
                          window.location.href=data.data;
                      }else {
                          layer.msg(data.msg);
                      }
                  }
              );
            return false;
          });

        $('#register').on('click', function () {
            layer.open({
                type: 2,    //弹出一个页面层
                title: "注册",
                content: '/register',
                area: ['500px', '500px'],
                anim: 1
            })
        })
    });
</script>
{% endblock %}